from copy import copy
from optparse import Option, OptionValueError
import datetime

def check_idate(option, opt, value):
    try:
    	d = datetime.datetime.strptime(value, '%d-%b-%Y')
        return value
    except ValueError:
        raise OptionValueError(
            "option %s: invalid imap-style date value: %r" % (opt, value))

class IDate (Option):
    TYPES = Option.TYPES + ("idate",)
    TYPE_CHECKER = copy(Option.TYPE_CHECKER)
    TYPE_CHECKER["idate"] = check_idate